package logic

import (
	"context"
	"everyone/B/rpc_B/model/mysql"

	"everyone/B/rpc_B/everyone"
	"everyone/B/rpc_B/internal/svc"

	"github.com/zeromicro/go-zero/core/logx"
)

type UserListLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewUserListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UserListLogic {
	return &UserListLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *UserListLogic) UserList(in *everyone.UserListRequest) (*everyone.UserListResponse, error) {
	// todo: add your logic here and delete this line
	u := mysql.User{}
	user, err := u.Find(in.UserStatue, in.Page, in.PageSize)
	if err != nil {
		logx.Error("用户查询失败")
	}
	var users []*everyone.UserItem
	for _, v := range user {
		users = append(users, &everyone.UserItem{
			UserName:   v.UserName,
			Phone:      v.Phone,
			Password:   v.Password,
			UserStatue: v.UserStatue,
		})
	}
	return &everyone.UserListResponse{
		UserLiset: users,
	}, nil
}
